.class public Lnet/oauth/client/httpclient4/HttpClient4;
.super Ljava/lang/Object;
.source "HttpClient4.java"

# interfaces
.implements Lnet/oauth/http/HttpClient;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lnet/oauth/client/httpclient4/HttpClient4$SingleClient;
    }
.end annotation


# static fields
.field private static final SHARED_CLIENT:Lnet/oauth/client/httpclient4/HttpClientPool;


# instance fields
.field private final clientPool:Lnet/oauth/client/httpclient4/HttpClientPool;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 108
    new-instance v0, Lnet/oauth/client/httpclient4/HttpClient4$SingleClient;

    invoke-direct {v0}, Lnet/oauth/client/httpclient4/HttpClient4$SingleClient;-><init>()V

    sput-object v0, Lnet/oauth/client/httpclient4/HttpClient4;->SHARED_CLIENT:Lnet/oauth/client/httpclient4/HttpClientPool;

    return-void
.end method

.method public constructor <init>()V
    .locals 1

    .prologue
    .line 52
    sget-object v0, Lnet/oauth/client/httpclient4/HttpClient4;->SHARED_CLIENT:Lnet/oauth/client/httpclient4/HttpClientPool;

    invoke-direct {p0, v0}, Lnet/oauth/client/httpclient4/HttpClient4;-><init>(Lnet/oauth/client/httpclient4/HttpClientPool;)V

    .line 53
    return-void
.end method

.method public constructor <init>(Lnet/oauth/client/httpclient4/HttpClientPool;)V
    .locals 0
    .parameter "clientPool"

    .prologue
    .line 55
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 56
    iput-object p1, p0, Lnet/oauth/client/httpclient4/HttpClient4;->clientPool:Lnet/oauth/client/httpclient4/HttpClientPool;

    .line 57
    return-void
.end method


# virtual methods
.method public execute(Lnet/oauth/http/HttpMessage;Ljava/util/Map;)Lnet/oauth/http/HttpResponseMessage;
    .locals 25
    .parameter "request"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lnet/oauth/http/HttpMessage;",
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Ljava/lang/Object;",
            ">;)",
            "Lnet/oauth/http/HttpResponseMessage;"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 62
    .local p2, parameters:Ljava/util/Map;,"Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;"
    move-object/from16 v0, p1

    iget-object v0, v0, Lnet/oauth/http/HttpMessage;->method:Ljava/lang/String;

    move-object/from16 v16, v0

    .line 63
    .local v16, method:Ljava/lang/String;
    move-object/from16 v0, p1

    iget-object v0, v0, Lnet/oauth/http/HttpMessage;->url:Ljava/net/URL;

    move-object/from16 v22, v0

    invoke-virtual/range {v22 .. v22}, Ljava/net/URL;->toExternalForm()Ljava/lang/String;

    move-result-object v20

    .line 64
    .local v20, url:Ljava/lang/String;
    invoke-virtual/range {p1 .. p1}, Lnet/oauth/http/HttpMessage;->getBody()Ljava/io/InputStream;

    move-result-object v3

    .line 65
    .local v3, body:Ljava/io/InputStream;
    const-string v22, "DELETE"

    move-object/from16 v0, v22

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v12

    .line 66
    .local v12, isDelete:Z
    const-string v22, "POST"

    move-object/from16 v0, v22

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v13

    .line 67
    .local v13, isPost:Z
    const-string v22, "PUT"

    move-object/from16 v0, v22

    move-object/from16 v1, v16

    invoke-virtual {v0, v1}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v14

    .line 68
    .local v14, isPut:Z
    const/4 v7, 0x0

    .line 70
    .local v7, excerpt:[B
    if-nez v13, :cond_0

    if-eqz v14, :cond_4

    .line 71
    :cond_0
    if-eqz v13, :cond_2

    new-instance v6, Lorg/apache/http/client/methods/HttpPost;

    move-object/from16 v0, v20

    invoke-direct {v6, v0}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    .line 72
    .local v6, entityEnclosingMethod:Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase;
    :goto_0
    if-eqz v3, :cond_1

    .line 73
    new-instance v5, Lnet/oauth/client/ExcerptInputStream;

    invoke-direct {v5, v3}, Lnet/oauth/client/ExcerptInputStream;-><init>(Ljava/io/InputStream;)V

    .line 74
    .local v5, e:Lnet/oauth/client/ExcerptInputStream;
    invoke-virtual {v5}, Lnet/oauth/client/ExcerptInputStream;->getExcerpt()[B

    move-result-object v7

    .line 75
    const-string v22, "Content-Length"

    move-object/from16 v0, p1

    move-object/from16 v1, v22

    invoke-virtual {v0, v1}, Lnet/oauth/http/HttpMessage;->removeHeaders(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v15

    .line 76
    .local v15, length:Ljava/lang/String;
    new-instance v24, Lorg/apache/http/entity/InputStreamEntity;

    if-nez v15, :cond_3

    const-wide/16 v22, -0x1

    :goto_1
    move-object/from16 v0, v24

    move-wide/from16 v1, v22

    invoke-direct {v0, v5, v1, v2}, Lorg/apache/http/entity/InputStreamEntity;-><init>(Ljava/io/InputStream;J)V

    move-object/from16 v0, v24

    invoke-virtual {v6, v0}, Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase;->setEntity(Lorg/apache/http/HttpEntity;)V

    .line 79
    .end local v5           #e:Lnet/oauth/client/ExcerptInputStream;
    .end local v15           #length:Ljava/lang/String;
    :cond_1
    move-object v9, v6

    .line 85
    .end local v6           #entityEnclosingMethod:Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase;
    .local v9, httpRequest:Lorg/apache/http/client/methods/HttpRequestBase;
    :goto_2
    move-object/from16 v0, p1

    iget-object v0, v0, Lnet/oauth/http/HttpMessage;->headers:Ljava/util/List;

    move-object/from16 v22, v0

    invoke-interface/range {v22 .. v22}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v11

    .local v11, i$:Ljava/util/Iterator;
    :goto_3
    invoke-interface {v11}, Ljava/util/Iterator;->hasNext()Z

    move-result v22

    if-eqz v22, :cond_6

    invoke-interface {v11}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v8

    check-cast v8, Ljava/util/Map$Entry;

    .line 86
    .local v8, header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    invoke-interface {v8}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v22

    check-cast v22, Ljava/lang/String;

    invoke-interface {v8}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v23

    check-cast v23, Ljava/lang/String;

    move-object/from16 v0, v22

    move-object/from16 v1, v23

    invoke-virtual {v9, v0, v1}, Lorg/apache/http/client/methods/HttpRequestBase;->addHeader(Ljava/lang/String;Ljava/lang/String;)V

    goto :goto_3

    .line 71
    .end local v8           #header:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/String;>;"
    .end local v9           #httpRequest:Lorg/apache/http/client/methods/HttpRequestBase;
    .end local v11           #i$:Ljava/util/Iterator;
    :cond_2
    new-instance v6, Lorg/apache/http/client/methods/HttpPut;

    move-object/from16 v0, v20

    invoke-direct {v6, v0}, Lorg/apache/http/client/methods/HttpPut;-><init>(Ljava/lang/String;)V

    goto :goto_0

    .line 76
    .restart local v5       #e:Lnet/oauth/client/ExcerptInputStream;
    .restart local v6       #entityEnclosingMethod:Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase;
    .restart local v15       #length:Ljava/lang/String;
    :cond_3
    invoke-static {v15}, Ljava/lang/Long;->parseLong(Ljava/lang/String;)J

    move-result-wide v22

    goto :goto_1

    .line 80
    .end local v5           #e:Lnet/oauth/client/ExcerptInputStream;
    .end local v6           #entityEnclosingMethod:Lorg/apache/http/client/methods/HttpEntityEnclosingRequestBase;
    .end local v15           #length:Ljava/lang/String;
    :cond_4
    if-eqz v12, :cond_5

    .line 81
    new-instance v9, Lorg/apache/http/client/methods/HttpDelete;

    move-object/from16 v0, v20

    invoke-direct {v9, v0}, Lorg/apache/http/client/methods/HttpDelete;-><init>(Ljava/lang/String;)V

    .restart local v9       #httpRequest:Lorg/apache/http/client/methods/HttpRequestBase;
    goto :goto_2

    .line 83
    .end local v9           #httpRequest:Lorg/apache/http/client/methods/HttpRequestBase;
    :cond_5
    new-instance v9, Lorg/apache/http/client/methods/HttpGet;

    move-object/from16 v0, v20

    invoke-direct {v9, v0}, Lorg/apache/http/client/methods/HttpGet;-><init>(Ljava/lang/String;)V

    .restart local v9       #httpRequest:Lorg/apache/http/client/methods/HttpRequestBase;
    goto :goto_2

    .line 88
    .restart local v11       #i$:Ljava/util/Iterator;
    :cond_6
    invoke-virtual {v9}, Lorg/apache/http/client/methods/HttpRequestBase;->getParams()Lorg/apache/http/params/HttpParams;

    move-result-object v19

    .line 89
    .local v19, params:Lorg/apache/http/params/HttpParams;
    invoke-interface/range {p2 .. p2}, Ljava/util/Map;->entrySet()Ljava/util/Set;

    move-result-object v22

    invoke-interface/range {v22 .. v22}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v11

    :cond_7
    :goto_4
    invoke-interface {v11}, Ljava/util/Iterator;->hasNext()Z

    move-result v22

    if-eqz v22, :cond_a

    invoke-interface {v11}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v18

    check-cast v18, Ljava/util/Map$Entry;

    .line 90
    .local v18, p:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/Object;>;"
    invoke-interface/range {v18 .. v18}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v17

    check-cast v17, Ljava/lang/String;

    .line 91
    .local v17, name:Ljava/lang/String;
    invoke-interface/range {v18 .. v18}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v22

    invoke-virtual/range {v22 .. v22}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v21

    .line 92
    .local v21, value:Ljava/lang/String;
    const-string v22, "followRedirects"

    move-object/from16 v0, v22

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v22

    if-eqz v22, :cond_8

    .line 93
    const-string v22, "http.protocol.handle-redirects"

    invoke-static/range {v21 .. v21}, Ljava/lang/Boolean;->parseBoolean(Ljava/lang/String;)Z

    move-result v23

    move-object/from16 v0, v19

    move-object/from16 v1, v22

    move/from16 v2, v23

    invoke-interface {v0, v1, v2}, Lorg/apache/http/params/HttpParams;->setBooleanParameter(Ljava/lang/String;Z)Lorg/apache/http/params/HttpParams;

    goto :goto_4

    .line 94
    :cond_8
    const-string v22, "readTimeout"

    move-object/from16 v0, v22

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v22

    if-eqz v22, :cond_9

    .line 95
    const-string v22, "http.socket.timeout"

    invoke-static/range {v21 .. v21}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v23

    move-object/from16 v0, v19

    move-object/from16 v1, v22

    move/from16 v2, v23

    invoke-interface {v0, v1, v2}, Lorg/apache/http/params/HttpParams;->setIntParameter(Ljava/lang/String;I)Lorg/apache/http/params/HttpParams;

    goto :goto_4

    .line 96
    :cond_9
    const-string v22, "connectTimeout"

    move-object/from16 v0, v22

    move-object/from16 v1, v17

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v22

    if-eqz v22, :cond_7

    .line 97
    const-string v22, "http.connection.timeout"

    invoke-static/range {v21 .. v21}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v23

    move-object/from16 v0, v19

    move-object/from16 v1, v22

    move/from16 v2, v23

    invoke-interface {v0, v1, v2}, Lorg/apache/http/params/HttpParams;->setIntParameter(Ljava/lang/String;I)Lorg/apache/http/params/HttpParams;

    goto :goto_4

    .line 101
    .end local v17           #name:Ljava/lang/String;
    .end local v18           #p:Ljava/util/Map$Entry;,"Ljava/util/Map$Entry<Ljava/lang/String;Ljava/lang/Object;>;"
    .end local v21           #value:Ljava/lang/String;
    :cond_a
    const-string v22, "http.protocol.expect-continue"

    const/16 v23, 0x0

    move-object/from16 v0, v19

    move-object/from16 v1, v22

    move/from16 v2, v23

    invoke-interface {v0, v1, v2}, Lorg/apache/http/params/HttpParams;->setBooleanParameter(Ljava/lang/String;Z)Lorg/apache/http/params/HttpParams;

    .line 103
    move-object/from16 v0, p0

    iget-object v0, v0, Lnet/oauth/client/httpclient4/HttpClient4;->clientPool:Lnet/oauth/client/httpclient4/HttpClientPool;

    move-object/from16 v22, v0

    new-instance v23, Ljava/net/URL;

    invoke-virtual {v9}, Lorg/apache/http/client/methods/HttpRequestBase;->getURI()Ljava/net/URI;

    move-result-object v24

    invoke-virtual/range {v24 .. v24}, Ljava/net/URI;->toString()Ljava/lang/String;

    move-result-object v24

    invoke-direct/range {v23 .. v24}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-interface/range {v22 .. v23}, Lnet/oauth/client/httpclient4/HttpClientPool;->getHttpClient(Ljava/net/URL;)Lorg/apache/http/client/HttpClient;

    move-result-object v4

    .line 104
    .local v4, client:Lorg/apache/http/client/HttpClient;
    invoke-interface {v4, v9}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v10

    .line 105
    .local v10, httpResponse:Lorg/apache/http/HttpResponse;
    new-instance v22, Lnet/oauth/client/httpclient4/HttpMethodResponse;

    invoke-virtual/range {p1 .. p1}, Lnet/oauth/http/HttpMessage;->getContentCharset()Ljava/lang/String;

    move-result-object v23

    move-object/from16 v0, v22

    move-object/from16 v1, v23

    invoke-direct {v0, v9, v10, v7, v1}, Lnet/oauth/client/httpclient4/HttpMethodResponse;-><init>(Lorg/apache/http/client/methods/HttpRequestBase;Lorg/apache/http/HttpResponse;[BLjava/lang/String;)V

    return-object v22
.end method
